#!/bin/sh
#
# Copyright (C) 2000-2025 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#
# Run four jobs at the same time, with two Volumes.
#   Set max Vol bytes of first volume
#   to less than total backup to force Bacula to use the second
#   Volume.
#
TestName="2drive-concurrent-test"
JobName=Four-concurrent-jobs
. scripts/functions

scripts/cleanup
scripts/copy-2disk-drive-confs
scripts/prepare-disk-changer
CLIENT=2drive2disk

echo "${cwd}/build" >${cwd}/tmp/file-list

change_jobname NightlySave $JobName
start_test

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@$out /dev/null
messages
@$out   ${cwd}/tmp/log1.out
label pool=Default storage=tape volume=TestVolume001 slot=1 drive=0
label pool=Default storage=tape volume=TestVolume002 slot=2 drive=1
update Volume=TestVolume001 MaxVolBytes=100000000
@#50000000
@#12
setdebug level=200 Storage=tape trace=1
status storage=tape
list jobs
list volumes
run job=$JobName level=Full Storage=tape
yes
@#reload
list jobs
list volumes
run job=$JobName level=Full Storage=tape
yes
@#reload
list jobs
list volumes
run job=$JobName level=Full Storage=tape
yes
@#reload
list jobs
list volumes
status storage=tape
run job=$JobName level=Full Storage=tape
yes
status storage=tape
@#reload
@#reload
@#reload
@#reload
@sleep 2
status dir
status storage=tape
@#reload
@sleep 5
list jobs
list volumes
messages
@#reload
@#reload
wait
status storage=tape
@#reload
messages
@# 
@# now do a restore
@#
@$out   ${cwd}/tmp/log2.out
status storage=tape
restore where=${cwd}/tmp/bacula-restores select storage=tape
unmark *
mark *
done
yes
wait
@#reload
@#reload
messages
@output
quit
END_OF_DATA

run_bacula
check_for_zombie_jobs storage=tape
stop_bacula

check_two_logs
check_restore_diff
end_test
